package com.rchat.pocmini.activity.view.location;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.rchat.pocmini.R;

/**
 * Created by ljd on 2017/3/10.
 *
 *
 */

public class CustomDialog1 extends Dialog {

    private Context mContext;
    private View.OnClickListener mListener;
    private View.OnClickListener mCancelListener;
    private String mMessage;
    private String mBtnStr="确定";
    private boolean isHideCancelBtn = false;
    private boolean isOverideDisMiss = false;

    private TextView tv_cancel;

    public CustomDialog1(Context context, String msg, View.OnClickListener confirmListener) {
        this(context, msg, "", confirmListener);
    }
    public CustomDialog1(Context context, String msg,String btnStr,View.OnClickListener confirmListener) {
        this(context, msg, "", confirmListener, null);
    }

    public CustomDialog1(Context context, String msg,String btnStr,View.OnClickListener confirmListener, boolean isHideCancelBtn,
                         boolean isOverideDisMiss) {
        super(context, R.style.Dialog);
        mContext = context;
        mMessage = msg;
        mListener = confirmListener;
        mBtnStr = btnStr;
        this.isHideCancelBtn = isHideCancelBtn;
        this.isOverideDisMiss = isOverideDisMiss;
    }

    public CustomDialog1(Context context, String msg,String btnStr,View.OnClickListener confirmListener, View.OnClickListener cancelListener) {
        super(context, R.style.Dialog);
        mContext = context;
        mMessage = msg;
        mListener = confirmListener;
        mCancelListener = cancelListener;
        mBtnStr = btnStr;
    }

    public CustomDialog1(Context context, int theme) {
        super(context, theme);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_confirm);
        //设置点击外面不取消
        setCanceledOnTouchOutside(false);

        TextView tv_msg = (TextView) findViewById(R.id.tv_msg);
        tv_msg.setText(mMessage);

        TextView tv_confirm = (TextView) findViewById(R.id.tv_confirm);
        if (mBtnStr!=null) {
            tv_confirm.setText(mBtnStr);
        }
        if (mListener == null) {
            tv_confirm.setOnClickListener(listener);
        } else {
            tv_confirm.setOnClickListener(mListener);
            dismiss();
        }

        tv_cancel = (TextView) findViewById(R.id.tv_cancel);

        if (isHideCancelBtn) {
            findViewById(R.id.divider).setVisibility(View.GONE);
            tv_cancel.setVisibility(View.GONE);
            tv_confirm.setBackgroundResource(R.drawable.bg_dialog1_ok2);
        }
        if (mCancelListener == null) {
            tv_cancel.setOnClickListener(listener);
        }else {
            tv_cancel.setOnClickListener(mCancelListener);
        }
    }

    public void isHideCancelBtn(boolean isHide){
        if (isHide) {
            tv_cancel.setVisibility(View.GONE);
        }
    }

    private View.OnClickListener listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            dismiss();
        }
    };


}

